﻿// Depends: Jquery.js

// 获取字符串字节数
function b_strlen(fData) {
    var intLength=0;
	for (var i=0;i<fData.length;i++)
	{
		if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255))
			intLength=intLength+2;
		else
			intLength=intLength+1;   
	}
	return intLength;
}

function win_strlen(content)
{
    var l = content.length;
    var nl = 0;
    
    if(content.match(/\n/g)!=null)
         nl = content.match(/\n/g).length;
    return (l+nl);
}

// 随机数
var WordsArr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
// 随机字母
function rndword() {
    return WordsArr.substr(rndnum(0,51),1);
}
// 随机字符串
function rndwords(len) {
    var rtn=[];
    for(i=0;i<len;i++)
    {
        rtn.push(rndword());
    }
    return rtn.join("");
}
// 随机数字
function rndnum(minnum,maxnum)
{
    return Math.ceil(Math.random()*(maxnum-minnum)+minnum);
}
function trim(text)
{
    if(typeof(text)=='undefined'|| !text.toString){ return ''; }
    return text.toString().replace(/^\s*|\s*$/g,'');
}

// 消息推送
var gloabl_i = 0;
var gloabl_t = document.title;
global_s = window.setInterval(
        function(){
        $.get("/InfoPushMonitor/AjaxGetMsgInfo", {rnd:rndnum(1,100000)},
            function(data)
            {
                if (data != "") 
                {
                    var info = data.split('\n');
                    if(info[0] != "0" || info[1] != "0")
                    {
                        var link;
                        if (info[0] != "0") link = "/Message/Inbox";
                        else link = "/message/systemmsg"; 
                        $("#newMsg").html("<a href=\"/Message\">新消息<span class=\"ico-message\">　　</span></a>|");
                    
                        window.setInterval(
                            function(){
                                document.title = gloabl_i % 2 ? "【　　　】 - "+ gloabl_t : "【新消息】 - " + gloabl_t ;
                                gloabl_i++;
                            },1000);
                        window.clearInterval(global_s);
                    }
                }
            }
          )
        },30000);


function showGetScore()
{
   $.get("/user/AjaxGetDailyScore", {rnd:rndnum(1,100000)}, function(data) {
      if (data == "success") 
      { 
        $("#span_score").html(parseInt($("#span_score").html()) + 20); 
        $("#span_getscore").hide();
        OpenAlertBoxByText("你已经成功领取20分积分<br><br><span style=\"color:gray\">温馨提示：每人每天有一次机会领取赠送积分，当天没有领取的积分不会累加。</span>","积分领取成功", 350);
      }
      else alert("领取失败");
    }, "TEXT" );
}

//变色龙，颜色变换器
function Chameleon(base)
{
    var valueCom = 0;
    if(base) valueCom = base;
    //浮点数颜色
    $.each( $(".colorFloat") , function(i, n)
    {        
        var value = $.trim($(n).text());
        if(value > valueCom)
        {
            $(n).attr("style","color:Red");
        }
        if(value < valueCom)
        {
            $(n).attr("style","color:Green");
        }
    }); 
    
    //百分数颜色
    $.each( $(".colorPercent") , function(i, n)
    {        
        var value = $.trim($(n).text());
        value = value.substring(0,value.length - 1);
        if(value > 0)
        {
            $(n).attr("style","color:Red");
        }
        if(value < 0)
        {
            $(n).attr("style","color:Green");
        }
    }); 
}